home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_023 / ver30 / word.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  6KB  |  268 lines

  1. /*
  2.  * Name:    MicroEMACS
  3.  *        Word mode commands.
  4.  * Version:    29
  5.  * Last edit:    05-Feb-86
  6.  * By:        rex::conroy
  7.  *        decvax!decwrl!dec-rhea!dec-rex!conroy
  8.  *
  9.  * The routines in this file
  10.  * implement commands that work word at
  11.  * a time. There are all sorts of word mode
  12.  * commands. If I do any sentence and/or paragraph
  13.  * mode commands, they are likely to be put in
  14.  * this file.
  15.  */
  16. #include    "def.h"
  17.  
  18. /*
  19.  * Move the cursor backward by
  20.  * "n" words. All of the details of motion
  21.  * are performed by the "backchar" and "forwchar"
  22.  * routines. Error if you try to move beyond
  23.  * the buffers.
  24.  */
  25. backword(f, n, k)
  26. {
  27.     if (n < 0)
  28.         return (forwword(f, -n, KRANDOM));
  29.     if (backchar(FALSE, 1, KRANDOM) == FALSE)
  30.         return (FALSE);
  31.     while (n--) {
  32.         while (inword() == FALSE) {
  33.             if (backchar(FALSE, 1, KRANDOM) == FALSE)
  34.                 return (FALSE);
  35.         }
  36.         while (inword() != FALSE) {
  37.             if (backchar(FALSE, 1, KRANDOM) == FALSE)
  38.                 return (FALSE);
  39.         }
  40.     }
  41.     return (forwchar(FALSE, 1, KRANDOM));
  42. }
  43.  
  44. /*
  45.  * Move the cursor forward by
  46.  * the specified number of words. All of the
  47.  * motion is done by "forwchar". Error if you
  48.  * try and move beyond the buffer's end.
  49.  */
  50. forwword(f, n, k)
  51. {
  52.     if (n < 0)
  53.         return (backword(f, -n, KRANDOM));
  54.     while (n--) {
  55.         while (inword() == FALSE) {
  56.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  57.                 return (FALSE);
  58.         }
  59.         while (inword() != FALSE) {
  60.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  61.                 return (FALSE);
  62.         }
  63.     }
  64.     return (TRUE);
  65. }
  66.  
  67. /*
  68.  * Move the cursor forward by
  69.  * the specified number of words. As you move,
  70.  * convert any characters to upper case. Error
  71.  * if you try and move beyond the end of the
  72.  * buffer.
  73.  */
  74. upperword(f, n, k)
  75. {
  76.     register int    c;
  77.  
  78.     if (n < 0)
  79.         return (FALSE);
  80.     while (n--) {
  81.         while (inword() == FALSE) {
  82.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  83.                 return (FALSE);
  84.         }
  85.         while (inword() != FALSE) {
  86.             c = lgetc(curwp->w_dotp, curwp->w_doto);
  87.             if (ISLOWER(c) != FALSE) {
  88.                 c = TOUPPER(c);
  89.                 lputc(curwp->w_dotp, curwp->w_doto, c);
  90.                 lchange(WFHARD);
  91.             }
  92.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  93.                 return (FALSE);
  94.         }
  95.     }
  96.     return (TRUE);
  97. }
  98.  
  99. /*
  100.  * Move the cursor forward by
  101.  * the specified number of words. As you move
  102.  * convert characters to lower case. Error if you
  103.  * try and move over the end of the buffer.
  104.  */
  105. lowerword(f, n, k)
  106. {
  107.     register int    c;
  108.  
  109.     if (n < 0)
  110.         return (FALSE);
  111.     while (n--) {
  112.         while (inword() == FALSE) {
  113.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  114.                 return (FALSE);
  115.         }
  116.         while (inword() != FALSE) {
  117.             c = lgetc(curwp->w_dotp, curwp->w_doto);
  118.             if (ISUPPER(c) != FALSE) {
  119.                 c = TOLOWER(c);
  120.                 lputc(curwp->w_dotp, curwp->w_doto, c);
  121.                 lchange(WFHARD);
  122.             }
  123.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  124.                 return (FALSE);
  125.         }
  126.     }
  127.     return (TRUE);
  128. }
  129.  
  130. /*
  131.  * Move the cursor forward by
  132.  * the specified number of words. As you move
  133.  * convert the first character of the word to upper
  134.  * case, and subsequent characters to lower case. Error
  135.  * if you try and move past the end of the buffer.
  136.  */
  137. capword(f, n, k)
  138. {
  139.     register int    c;
  140.  
  141.     if (n < 0)
  142.         return (FALSE);
  143.     while (n--) {
  144.         while (inword() == FALSE) {
  145.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  146.                 return (FALSE);
  147.         }
  148.         if (inword() != FALSE) {
  149.             c = lgetc(curwp->w_dotp, curwp->w_doto);
  150.             if (ISLOWER(c) != FALSE) {
  151.                 c = TOUPPER(c);
  152.                 lputc(curwp->w_dotp, curwp->w_doto, c);
  153.                 lchange(WFHARD);
  154.             }
  155.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  156.                 return (FALSE);
  157.             while (inword() != FALSE) {
  158.                 c = lgetc(curwp->w_dotp, curwp->w_doto);
  159.                 if (ISUPPER(c) != FALSE) {
  160.                     c = TOLOWER(c);
  161.                     lputc(curwp->w_dotp, curwp->w_doto, c);
  162.                     lchange(WFHARD);
  163.                 }
  164.                 if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  165.                     return (FALSE);
  166.             }
  167.         }
  168.     }
  169.     return (TRUE);
  170. }
  171.  
  172. /*
  173.  * Kill forward by "n" words. The rules for final
  174.  * status are now different. It is not considered an error
  175.  * to delete fewer words than you asked. This lets you say
  176.  * "kill lots of words" and have the command stop in a reasonable
  177.  * way when it hits the end of the buffer. Normally this is
  178.  */
  179. delfword(f, n, k)
  180. {
  181.     register int    size;
  182.     register LINE    *dotp;
  183.     register int    doto;
  184.  
  185.     if (n < 0)
  186.         return (FALSE);
  187.     if ((lastflag&CFKILL) == 0)        /* Purge kill buffer.    */
  188.         kdelete();
  189.     thisflag |= CFKILL;
  190.     dotp = curwp->w_dotp;
  191.     doto = curwp->w_doto;
  192.     size = 0;
  193.     while (n--) {
  194.         while (inword() == FALSE) {
  195.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  196.                 goto out;    /* Hit end of buffer.    */
  197.             ++size;
  198.         }
  199.         while (inword() != FALSE) {
  200.             if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  201.                 goto out;    /* Hit end of buffer.    */
  202.             ++size;
  203.         }
  204.     }
  205. out:
  206.     curwp->w_dotp = dotp;
  207.     curwp->w_doto = doto;
  208.     return (ldelete(size, TRUE));
  209. }
  210.  
  211. /*
  212.  * Kill backwards by "n" words. The rules
  213.  * for success and failure are now different, to prevent
  214.  * strange behavior at the start of the buffer. The command
  215.  * only fails if something goes wrong with the actual delete
  216.  * of the characters. It is successful even if no characters
  217.  * are deleted, or if you say delete 5 words, and there are
  218.  * only 4 words left. I considered making the first call
  219.  * to "backchar" special, but decided that that would just
  220.  * be wierd. Normally this is bound to "M-Rubout" and
  221.  * to "M-Backspace".
  222.  */
  223. delbword(f, n, k)
  224. {
  225.     register int    size;
  226.  
  227.     if (n < 0)
  228.         return (FALSE);
  229.     if ((lastflag&CFKILL) == 0)        /* Purge kill buffer.    */
  230.         kdelete();
  231.     thisflag |= CFKILL;
  232.     if (backchar(FALSE, 1, KRANDOM) == FALSE)
  233.         return (TRUE);            /* Hit buffer start.    */
  234.     size = 1;                /* One deleted.        */
  235.     while (n--) {
  236.         while (inword() == FALSE) {
  237.             if (backchar(FALSE, 1, KRANDOM) == FALSE)
  238.                 goto out;    /* Hit buffer start.    */
  239.             ++size;
  240.         }
  241.         while (inword() != FALSE) {
  242.             if (backchar(FALSE, 1, KRANDOM) == FALSE)
  243.                 goto out;    /* Hit buffer start.    */
  244.             ++size;
  245.         }
  246.     }
  247.     if (forwchar(FALSE, 1, KRANDOM) == FALSE)
  248.         return (FALSE);
  249.     --size;                    /* Undo assumed delete.    */
  250. out:
  251.     return (ldelete(size, TRUE));
  252. }
  253.  
  254. /*
  255.  * Return TRUE if the character at dot
  256.  * is a character that is considered to be
  257.  * part of a word. The word character list is hard
  258.  * coded. Should be setable.
  259.  */
  260. inword()
  261. {
  262.     if (curwp->w_doto == llength(curwp->w_dotp))
  263.         return (FALSE);
  264.     if (ISWORD(lgetc(curwp->w_dotp, curwp->w_doto)) != FALSE)
  265.         return (TRUE);
  266.     return (FALSE);
  267. }
  268.